package com.sangfor.ssl.easyapp;

import android.app.Application;
import android.content.Context;
import android.os.Looper;
import android.text.TextUtils;
import com.sangfor.bugreport.logger.Log;
import com.sangfor.ssl.ChangePasswordResult;
import com.sangfor.ssl.ISangforAuth;
import com.sangfor.ssl.IVpnDelegate;
import com.sangfor.ssl.SFException;
import com.sangfor.ssl.rdp.utils.crypto.Crypto;
import com.sangfor.ssl.service.setting.ResourceManager;
import java.util.Iterator;
import java.util.List;

/* loaded from: classes2.dex */
public class SangforNbAuth extends SangforAuthForward implements ISangforAuth {
    private static final String CHANGE_PASSWORD_SUCCESS = "修改密码成功";
    private static final int STATUS_OFFLINE = 1;
    private static final int STATUS_ONLINE = 0;
    private static final String TAG = "SangforNbAuth";

    @Override // com.sangfor.ssl.ISangforAuth
    public boolean vpnL3vpnStart() {
        return false;
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public boolean vpnLogoutInTime() {
        return false;
    }

    private SangforNbAuth() {
    }

    public static SangforNbAuth getInstance() {
        SangforNbAuth sangforNbAuth;
        synchronized (SangforNbAuth.class) {
            if (instance == null || !(instance instanceof SangforNbAuth)) {
                instance = new SangforNbAuth();
            }
            sangforNbAuth = (SangforNbAuth) instance;
        }
        return sangforNbAuth;
    }

    @Override // com.sangfor.ssl.easyapp.SangforAuthForward, com.sangfor.ssl.ISangforAuth
    public boolean setDelegate(IVpnDelegate iVpnDelegate) {
        return super.setDelegate(iVpnDelegate);
    }

    @Override // com.sangfor.ssl.easyapp.SangforAuthForward, com.sangfor.ssl.ISangforAuth
    public IVpnDelegate getDelegate() {
        return super.getDelegate();
    }

    @Override // com.sangfor.ssl.easyapp.SangforAuthForward, com.sangfor.ssl.ISangforAuth
    public void init(Application application, Context context, IVpnDelegate iVpnDelegate, int i) throws SFException {
        clearAuthProperties();
        super.init(application, context, iVpnDelegate, i);
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public boolean vpnInit(long j, int i) {
        if (Looper.myLooper() != Looper.getMainLooper()) {
            Log.info(TAG, "vpnInit, current thread is not main thread.");
            return false;
        }
        return super.vpnInit(j, i, true);
    }

    @Override // com.sangfor.ssl.easyapp.SangforAuthForward, com.sangfor.ssl.ISangforAuth
    public boolean setLoginParam(String str, String str2) {
        if (Looper.myLooper() != Looper.getMainLooper()) {
            Log.info(TAG, "setLoginParam, current thread is not main thread.");
            return false;
        }
        if (str.equals(IVpnDelegate.TWF_AUTH_TWFID) && !TextUtils.isEmpty(str2)) {
            str2 = new Crypto("SangforAxzq").decrypt(str2);
        }
        return nSetLoginParam(str, str2, true) == 0;
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public boolean vpnLogin(int i) {
        if (Looper.myLooper() != Looper.getMainLooper()) {
            Log.info(TAG, "vpnLogin, current thread is not main thread.");
            return false;
        }
        String encrypt = new Crypto("sangfor").encrypt(vpnGetHardwareId());
        String str = TAG;
        Log.info(str, "mobileid: " + encrypt);
        setMobileId(encrypt);
        if (i != 3) {
            return nVpnLogin(i, true) == 0;
        }
        vpnRegetSmsCode();
        return true;
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public int vpnRegetSmsCodeBlock() {
        return nRegetSmsCode();
    }

    @Override // com.sangfor.ssl.easyapp.SangforAuthForward, com.sangfor.ssl.ISangforAuth
    public boolean vpnCancelLogin() {
        if (Looper.myLooper() == Looper.getMainLooper()) {
            return nVpnCancelLogin(true) == 0;
        }
        Log.info(TAG, "vpnCancelLogin, current thread is not main thread.");
        return false;
    }

    @Override // com.sangfor.ssl.easyapp.SangforAuthForward, com.sangfor.ssl.ISangforAuth
    public boolean vpnLogout() {
        if (Looper.myLooper() != Looper.getMainLooper()) {
            Log.error(TAG, "call vpnLogout failed, current thread is not main thread.");
            return false;
        }
        return super.vpnLogout();
    }

    @Override // com.sangfor.ssl.easyapp.SangforAuthForward, com.sangfor.ssl.ISangforAuth
    public boolean vpnQuit() {
        mContext = null;
        this.mDelegate = null;
        mHandler = null;
        return nVpnQuit(true) == 0;
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public int vpnQueryStatus() {
        return queryVPNLocalStatus();
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public int queryVpnStatus() {
        int queryVPNLocalStatus = queryVPNLocalStatus();
        return queryVPNLocalStatus != 5 ? (queryVPNLocalStatus == 12 || queryVPNLocalStatus == 100) ? 12 : 13 : sL3vpnMode ? 13 : 12;
    }

    @Override // com.sangfor.ssl.easyapp.SangforAuthForward
    public String vpnQueryHardID() {
        return nVpnQueryHardID(true);
    }

    @Override // com.sangfor.ssl.easyapp.SangforAuthForward, com.sangfor.ssl.ISangforAuth
    public int vpnGetRndCode() {
        return nVpnGetRndCode(true);
    }

    @Override // com.sangfor.ssl.easyapp.SangforAuthForward, com.sangfor.ssl.ISangforAuth
    public String vpnGeterr() {
        return super.vpnGeterr();
    }

    @Override // com.sangfor.ssl.easyapp.SangforAuthForward, com.sangfor.ssl.ISangforAuth
    public int vpnGetErrorCode() {
        return super.vpnGetErrorCode();
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public void vpnSeterr(String str) {
        nVpnSeterr(str, true);
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public String vpnGetSdkVersion() {
        return nVpnGetVersion(true);
    }

    @Override // com.sangfor.ssl.easyapp.SangforAuthForward, com.sangfor.ssl.ISangforAuth
    public void onActivityResult(int i, int i2) {
        super.onActivityResult(i, i2);
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public String getSmsPhoneNum() {
        return nGetSmsPhoneNum();
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public String getSmsCountDown() {
        return nGetSmsCountdown();
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public String getTwfid() {
        return new Crypto("SangforAxzq").encrypt(nGetTwfid());
    }

    @Override // com.sangfor.ssl.easyapp.SangforAuthForward, com.sangfor.ssl.ISangforAuth
    public Context getContext() {
        return super.getContext();
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public String getPastAuthEmm() {
        return vpnGetPastAuthEmm();
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public String getLocalRclist(boolean z) {
        return super.nGetLocalRclist(z);
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public String vpnGetCertSubject(String str, String str2) {
        return super.getCertSubject(str, str2);
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public String getPasswordPolicy() {
        return nGetPasswordPolicy();
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public void clearSession() {
        nCleanSession();
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public boolean setDnsWhiteList(List<String> list) {
        Iterator<String> it;
        String str = "";
        if (list != null) {
            while (list.iterator().hasNext()) {
                str = it.next() + ";";
            }
        }
        if (!TextUtils.isEmpty(str)) {
            str = str.substring(0, str.length() - 1);
        }
        ResourceManager.getInstance().setmDnsWihteRule(str);
        return nSetDnsWhiteRule(str);
    }

    public void clearAuthProperties() {
        nClearAuthProperties();
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public String getChallengeMessage() {
        return nGetChallengeMessage();
    }

    @Override // com.sangfor.ssl.ISangforAuth
    public ChangePasswordResult changePassword(String str, String str2) {
        ChangePasswordResult changePasswordResult = new ChangePasswordResult();
        String nChangePassword = nChangePassword(str, str2);
        if (nChangePassword.equals(CHANGE_PASSWORD_SUCCESS)) {
            changePasswordResult.setSuccess(true);
        } else {
            changePasswordResult.setSuccess(false);
        }
        changePasswordResult.setResultStr(nChangePassword);
        return changePasswordResult;
    }
}
